/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.common.json;

import com.entities.EventLibrary;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

/**
 *
 * @author NguyenVan
 */
public class EventLibraryJson {
    public static EventLibrary convertJSONObjectStringToEventLibraryForFillEventsDataTable(String jsonstr) {
        try {            
            JSONParser parser = new JSONParser();
            JSONObject json = (JSONObject) parser.parse(jsonstr);            
            String idstr = json.get("eventId").toString();           
            int id = Integer.parseInt(idstr);            
            String name = json.get("name").toString();            
            String des = json.get("description").toString();            
            String type = json.get("eventType").toString();            
            String timeS = json.get("start").toString();            
            String timeE = json.get("end").toString();              
//            String registeredStr = json.get("registered").toString();            
//            int reg = Integer.parseInt(registeredStr);
            EventLibrary obj = new EventLibrary(id, name, des, type, timeS, timeE);
            return obj;
        } catch (ParseException ex) {
            Logger.getLogger(EventLibraryJson.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
